package com.example.lushiping2.controller;

import com.example.lushiping2.bean.Person;
import com.example.lushiping2.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class HelloController {
    @Autowired
    HelloService helloService;

    @GetMapping("/getAllPerson")
    public List<Person> getAllPerson(){
        return helloService.getAllPerson();
    }

    @GetMapping("/{id}/getPerson")
    public Person getPerson(@PathVariable("id") Integer id){
        return helloService.getPerson(id);
    }

    @PostMapping("/insertPerson/{username}/{userpasswd}")
    public void insertPerson(@PathVariable("username") String username,
                             @PathVariable("userpasswd") String userpasswd){
        helloService.insertPerson(username,userpasswd);
    }

    @GetMapping("/selectUsername/{username}/{userPassword}")
    public Person selectUsername(@PathVariable("username") String username,
                                 @PathVariable("userPassword") String userpasswd){
        return helloService.selectUsername(username, userpasswd);
    }
}
